import { getView } from '@/api/view'

const state = {
  viewList: [],
  viewCount: 0,
  selectionList: []
}

const mutations = {
  update(state, payload) {
    console.log(payload)
    for (const key in payload) {
      state[key] = payload[key]
    }
  }
}

const actions = {
  async getView({ commit }, payload = {}) {
    const { page, options, pageSize } = payload
    const result = await getView(page, options, pageSize)
    if (result.data) {
      commit('update', {
        viewList: result.data[0],
        viewCount: result.data[1]
      })
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
